﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Samples.ServiceHosting.StorageClient;
using Microsoft.ServiceHosting.ServiceRuntime;

namespace UlyssesAgenda.Storage.Blob
{
    public static class GameBlobStorage
    {
        public static BlobProperties[] GetBlobsInContainer(BlobContainer blobContainer)
        {
            return GetBlobsInContainer(string.Empty, blobContainer);
        }

        public static BlobProperties[] GetBlobsInContainer(string prefix, BlobContainer blobContainer)
        {
            List<BlobProperties> blobPropsList = new List<BlobProperties>();
            IEnumerable<object> blobs = blobContainer.ListBlobs(prefix, false); 
            
            foreach (object blobObject in blobs)
            {
                BlobProperties props = blobObject as BlobProperties;
                if (props != null)
                {
                    BlobProperties blobProps = blobContainer.GetBlobProperties(props.Name);
                    blobPropsList.Add(blobProps);
                }
            }
            return blobPropsList.ToArray();
        }
    }
}
